/**
 * 2017年5月7日
 */
package util.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

import org.lab.libsvm.svm_node;

/**
 * @author Alex
 *
 */
public class SVMNodesWriter {
	/**
	 * @throws IOException 
	 * 
	 */
	public SVMNodesWriter(File f,	Vector<svm_node[]> vx,Vector<Double> vy) throws IOException {
		try(FileWriter fw = new FileWriter(f)){
			for(int i=0;i<vy.size();i++){
				fw.write(String.valueOf(vy.get(i)));
				fw.write(" ");
				svm_node[] sn = vx.get(i);
				for(int j=0;j<sn.length;j++){
					fw.write(String.valueOf(sn[j].index));
					fw.write(":");
					fw.write(String.valueOf(sn[j].value));
					if(j<sn.length-1){
						fw.write(" ");
					}
				}
				fw.write("\r\n");
				
			}
		}
	}
}
